<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>路由器机制</title>
	</head>
	<body>
		<div id="app">
			<!-- 2.定义路由连接
			 router-link 解析后,变为a标签
			 to 解析之后,变为href属性-->
			<router-link to="/user">用户</router-link>
			<router-link to="/dog">狗狗</router-link>
			<router-view></router-view>
		</div>
		<!-- 4.2定义组件模板 -->
		<template id="userTem">
			<div>
				<h1>我是组件内容</h1>
			</div>
		</template>
		<template id="dogTem">
			<div>
				<h1>狗狗狗狗狗</h1>
			</div>
		</template>



		<!-- 1.引入vue.js -->
		<script src="https://cdn.jsdelivr.net/npm/vue@2" type="text/javascript" charset="utf-8"></script>
		<!-- 2.导入路由js 注意顺序 -->
		<script src="../js/vue-router.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			//4.定义组件
			let user = {
				//4.1定义页面
				template: "#userTem"
			}
			let dog = {
				
				template: "#dogTem"
			}
			//5.创建路由对象,定义路由规则
			let router = new VueRouter({
				//利用redirect实现路由重定向
				routes: [{path:"/",redirect: "/dog"},
					{path: "/user",component: user},
				         {path: "/dog",component: dog}]
			})
			//6.将路由对象交给vue对象管理
			const vue = new Vue({
				el: "#app",
				//绑定路由
				//router: router 名称一致时,可以简化
				router
			})
		</script>
	</body>
</html>
